#!usr/bin/env python  
# -*- coding:utf-8 -*-

from django.template import Library
from ..models import Notice, FriendLinks
from bbd_admin.models import SiteSetting

from django.utils.safestring import mark_safe

register = Library()


@register.simple_tag()
def notice_tag():
    notice = Notice.objects.all().first()

    return mark_safe('暂无公告' if not notice else notice.text)


@register.simple_tag()
def friendship_links():
    """
    友情链接
    :return:
    """
    dispaly_links = []
    links = FriendLinks.objects.all()
    for link in links:
        params = {'name': link.name, 'url': link.url}
        a_ele = '<a href="{url}" target="_blank" class="friendships">{name}</a>'
        dispaly_links.append(a_ele.format(**params))
    return mark_safe(''.join(dispaly_links))
